<script setup>
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const popularDestinations = ref([]);
const featuredTours = ref([]);
const loading = ref(true);

// 模拟热门目的地数据
const mockDestinations = [
  {
    id: 1,
    name: '北京',
    image: '/travel-images/1 (5).png',
    tourCount: 128
  },
  {
    id: 2,
    name: '上海',
    image: '/travel-images/1 (6).png',
    tourCount: 156
  },
  {
    id: 3,
    name: '杭州',
    image: '/travel-images/1 (8).png',
    tourCount: 98
  },
  {
    id: 4,
    name: '成都',
    image: '/travel-images/1 (9).png',
    tourCount: 112
  }
];

// 模拟特色行程数据
const mockTours = [
  {
    id: 1,
    title: '北京5日经典游',
    price: 2999,
    days: 5,
    image: '/travel-images/1 (5).png',
    rating: 4.8,
    reviewCount: 235
  },
  {
    id: 2,
    title: '上海迪士尼乐园2日游',
    price: 1899,
    days: 2,
    image: '/travel-images/1 (6).png',
    rating: 4.9,
    reviewCount: 342
  },
  {
    id: 3,
    title: '杭州西湖+千岛湖3日游',
    price: 1699,
    days: 3,
    image: '/travel-images/1 (8).png',
    rating: 4.7,
    reviewCount: 189
  },
  {
    id: 4,
    title: '成都+九寨沟6日游',
    price: 3499,
    days: 6,
    image: '/travel-images/1 (9).png',
    rating: 4.9,
    reviewCount: 278
  }
];

// 获取数据
const fetchData = () => {
  loading.value = true;
  // 模拟API请求延迟
  setTimeout(() => {
    popularDestinations.value = mockDestinations;
    featuredTours.value = mockTours;
    loading.value = false;
  }, 500);
};

// 跳转到目的地详情
const goToDestination = (id) => {
  router.push(`/destination/${id}`);
};

// 跳转到行程详情
const goToTourDetail = (id) => {
  // 实际项目中这里应该跳转到行程详情页
  alert(`查看行程ID: ${id}的详情`);
};

// 组件挂载时获取数据
onMounted(() => {
  fetchData();
});
</script>

<template>
  <div class="travel-container">
    <!-- 搜索区域 -->
    <div class="search-section">
      <div class="search-box">
        <h2>开启您的精彩旅程</h2>
        <p>搜索目的地、行程或旅行服务</p>
        <div class="search-form">
          <input type="text" placeholder="输入目的地、景点或行程" />
          <button class="search-btn">搜索</button>
        </div>
      </div>
    </div>
    
    <!-- 热门目的地 -->
    <section class="section">
      <div class="section-header">
        <h2>热门目的地</h2>
        <router-link to="/destination" class="more-link">查看更多</router-link>
      </div>
      
      <div v-if="loading" class="loading">
        <p>加载中...</p>
      </div>
      
      <div v-else class="destination-scroll">
        <div 
          v-for="dest in popularDestinations" 
          :key="dest.id" 
          class="destination-item"
          @click="goToDestination(dest.id)"
        >
          <div class="dest-image">
            <img :src="dest.image" :alt="dest.name" />
            <div class="dest-overlay">{{ dest.name }}</div>
          </div>
          <p class="dest-info">{{ dest.tourCount }}个行程</p>
        </div>
      </div>
    </section>
    
    <!-- 特色行程 -->
    <section class="section">
      <div class="section-header">
        <h2>特色行程推荐</h2>
        <a href="#" class="more-link">查看更多</a>
      </div>
      
      <div v-if="loading" class="loading">
        <p>加载中...</p>
      </div>
      
      <div v-else class="tours-grid">
        <div 
          v-for="tour in featuredTours" 
          :key="tour.id" 
          class="tour-card"
          @click="goToTourDetail(tour.id)"
        >
          <div class="tour-image">
            <img :src="tour.image" :alt="tour.title" />
            <span class="tour-days">{{ tour.days }}天</span>
          </div>
          <div class="tour-content">
            <h3 class="tour-title">{{ tour.title }}</h3>
            <div class="tour-rating">
              <span class="star">★</span>
              <span>{{ tour.rating }}</span>
              <span class="review-count">({{ tour.reviewCount }}条评价)</span>
            </div>
            <div class="tour-footer">
              <div class="price">
                <span class="price-symbol">¥</span>
                <span class="price-value">{{ tour.price }}</span>
                <span class="price-unit">起/人</span>
              </div>
              <button class="book-btn">立即预订</button>
            </div>
          </div>
        </div>
      </div>
    </section>
    
    <!-- 旅行服务 -->
    <section class="section service-section">
      <div class="section-header">
        <h2>旅行服务</h2>
      </div>
      
      <div class="services-grid">
        <div class="service-item">
          <div class="service-icon">🏨</div>
          <h3>酒店预订</h3>
          <p>全球海量酒店，价格优惠</p>
        </div>
        <div class="service-item">
          <div class="service-icon">✈️</div>
          <h3>机票查询</h3>
          <p>实时比价，便捷预订</p>
        </div>
        <div class="service-item">
          <div class="service-icon">🚗</div>
          <h3>租车服务</h3>
          <p>便捷租车，自驾游无忧</p>
        </div>
        <div class="service-item">
          <div class="service-icon">🎫</div>
          <h3>门票预订</h3>
          <p>热门景点门票，一键预订</p>
        </div>
      </div>
    </section>
    
    <!-- 用户评价 -->
    <section class="section review-section">
      <div class="section-header">
        <h2>旅行者评价</h2>
      </div>
      
      <div class="reviews-scroll">
        <div class="review-item">
          <div class="reviewer-info">
            <div class="reviewer-avatar">👩‍💼</div>
            <div class="reviewer-meta">
              <h4>张女士</h4>
              <div class="reviewer-rating">★★★★★</div>
            </div>
          </div>
          <p class="review-content">这次北京之行非常愉快，导游服务专业，行程安排合理，有充足的自由活动时间，推荐给大家！</p>
          <p class="review-tour">北京5日经典游</p>
        </div>
        <div class="review-item">
          <div class="reviewer-info">
            <div class="reviewer-avatar">👨‍💼</div>
            <div class="reviewer-meta">
              <h4>李先生</h4>
              <div class="reviewer-rating">★★★★★</div>
            </div>
          </div>
          <p class="review-content">上海迪士尼的行程安排得很到位，避开了人流高峰，孩子们玩得很开心，物超所值！</p>
          <p class="review-tour">上海迪士尼乐园2日游</p>
        </div>
        <div class="review-item">
          <div class="reviewer-info">
            <div class="reviewer-avatar">👩‍🎓</div>
            <div class="reviewer-meta">
              <h4>王同学</h4>
              <div class="reviewer-rating">★★★★☆</div>
            </div>
          </div>
          <p class="review-content">杭州的风景真的很美，特别是西湖，导游讲解很详细，让我对杭州的历史文化有了更深的了解。</p>
          <p class="review-tour">杭州西湖+千岛湖3日游</p>
        </div>
      </div>
    </section>
  </div>
</template>

<style scoped>
.travel-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0;
}

/* 搜索区域样式 */
.search-section {
  background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('/travel-images/1-1.png');
  background-size: cover;
  background-position: center;
  padding: 80px 0;
  text-align: center;
}

.search-box {
  max-width: 800px;
  margin: 0 auto;
  color: white;
}

.search-box h2 {
  font-size: 36px;
  margin-bottom: 10px;
}

.search-box p {
  font-size: 18px;
  margin-bottom: 30px;
}

.search-form {
  display: flex;
  max-width: 600px;
  margin: 0 auto;
}

.search-form input {
  flex: 1;
  padding: 15px 20px;
  border: none;
  border-radius: 4px 0 0 4px;
  font-size: 16px;
}

.search-btn {
  padding: 15px 30px;
  background-color: #ff9c00;
  color: white;
  border: none;
  border-radius: 0 4px 4px 0;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.search-btn:hover {
  background-color: #e68a00;
}

/* 通用区块样式 */
.section {
  padding: 60px 20px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.section-header h2 {
  font-size: 28px;
  color: #333;
}

.more-link {
  color: #ff9c00;
  text-decoration: none;
  font-size: 16px;
}

.more-link:hover {
  text-decoration: underline;
}

.loading {
  text-align: center;
  padding: 50px;
  color: #666;
}

/* 热门目的地样式 */
.destination-scroll {
  display: flex;
  gap: 20px;
  overflow-x: auto;
  padding-bottom: 20px;
}

.destination-item {
  min-width: 200px;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.destination-item:hover {
  transform: translateY(-5px);
}

.dest-image {
  position: relative;
  height: 250px;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}

.dest-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.destination-item:hover .dest-image img {
  transform: scale(1.05);
}

.dest-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 15px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  color: white;
  font-size: 18px;
  font-weight: bold;
}

.dest-info {
  text-align: center;
  color: #666;
  font-size: 14px;
}

/* 特色行程样式 */
.tours-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 30px;
}

.tour-card {
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
}

.tour-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
}

.tour-image {
  position: relative;
  height: 180px;
  overflow: hidden;
}

.tour-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.tour-card:hover .tour-image img {
  transform: scale(1.05);
}

.tour-days {
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: #ff9c00;
  color: white;
  padding: 5px 12px;
  border-radius: 15px;
  font-size: 12px;
  font-weight: bold;
}

.tour-content {
  padding: 20px;
}

.tour-title {
  font-size: 18px;
  color: #333;
  margin-bottom: 10px;
}

.tour-rating {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 15px;
  font-size: 14px;
  color: #666;
}

.tour-rating .star {
  color: #ffd700;
}

.review-count {
  color: #999;
  font-size: 12px;
}

.tour-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.price {
  display: flex;
  align-items: baseline;
  color: #ff6b6b;
}

.price-symbol {
  font-size: 14px;
  margin-right: 2px;
}

.price-value {
  font-size: 24px;
  font-weight: bold;
  margin-right: 2px;
}

.price-unit {
  font-size: 12px;
  color: #666;
}

.book-btn {
  padding: 8px 20px;
  background-color: #ff9c00;
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.book-btn:hover {
  background-color: #e68a00;
}

/* 旅行服务样式 */
.service-section {
  background-color: #f8f8f8;
}

.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 30px;
}

.service-item {
  text-align: center;
  padding: 30px;
  background-color: white;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
  cursor: pointer;
}

.service-item:hover {
  transform: translateY(-5px);
}

.service-icon {
  font-size: 48px;
  margin-bottom: 20px;
}

.service-item h3 {
  font-size: 18px;
  color: #333;
  margin-bottom: 10px;
}

.service-item p {
  color: #666;
  font-size: 14px;
}

/* 用户评价样式 */
.review-section {
  background-color: #fff5e6;
}

.reviews-scroll {
  display: flex;
  gap: 30px;
  overflow-x: auto;
  padding-bottom: 20px;
}

.review-item {
  min-width: 300px;
  background-color: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.reviewer-info {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.reviewer-avatar {
  font-size: 48px;
}

.reviewer-meta h4 {
  margin: 0 0 5px 0;
  color: #333;
}

.reviewer-rating {
  color: #ffd700;
  font-size: 16px;
}

.review-content {
  color: #666;
  line-height: 1.6;
  margin-bottom: 20px;
}

.review-tour {
  color: #ff9c00;
  font-size: 14px;
  font-weight: bold;
}

@media (max-width: 768px) {
  .search-box h2 {
    font-size: 24px;
  }
  
  .search-form {
    flex-direction: column;
  }
  
  .search-form input {
    border-radius: 4px;
    margin-bottom: 10px;
  }
  
  .search-btn {
    border-radius: 4px;
  }
  
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  
  .section-header h2 {
    font-size: 24px;
  }
  
  .tours-grid {
    grid-template-columns: 1fr;
  }
  
  .services-grid {
    grid-template-columns: 1fr;
  }
}
</style>